package cz.cvut.fit.mi.dpo.mvc.model.elements;

import java.util.*;

/**
 * @author David Pertl
 * @author Martin Štekl <steklmar@fit.cvut.cz>
 */
public class ElementCollection<T extends AElement> implements Iterable<T> {

	private Map<Integer, T> map = new LinkedHashMap<Integer, T>();

	public ElementCollection add(T element) {
		map.put(element.getId(), element);
		return this;
	}

	public T get(int index) {
		List<T> list = new ArrayList<T>(map.values());
		return list.get(index);
	}

	public T getById(int id) {
		return map.get(id);
	}

	public int size() {
		return map.size();
	}

	@Override
	public Iterator<T> iterator() {
		return map.values().iterator();
	}

}
